package com.mall.dto;

import com.mall.entity.PmsProduct;
import com.mall.entity.PmsSkuStock;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
public class FrontProductDetailDto {
    @ApiModelProperty(value = "商品id")
    private Long id;
    @ApiModelProperty(value = "商品名称")
    private String name;
    @ApiModelProperty(value = "商品子标题")
    private String subtitle;
    @ApiModelProperty(value = "商品主图")
    private String pic;
    @ApiModelProperty(value = "商品详情")
    private String detailHtml;
    @ApiModelProperty(value = "商品价格")
    private BigDecimal price;
    @ApiModelProperty(value = "商品促销价格")
    private BigDecimal promotionPrice;
    @ApiModelProperty(value = "促销开始时间")
    private Date promotion_start_time;
    @ApiModelProperty(value = "促销结束时间")
    private Date promotion_end_time;
    @ApiModelProperty(value = "商品评论数")
    private int commentCount;
    @ApiModelProperty(value = "分类属性列表")
    private List<FrontCateAttributeDto> frontCateAttributeDto;
    @ApiModelProperty(value = "商品库存")
    private List<FrontStockDto> stockList;
    @ApiModelProperty(value = "商品评价")
    private List<FrontCommentDto> frontCommentDtoList;

    public void setProduct(PmsProduct product) {
        this.id = product.getId();
        this.name = product.getName();
        this.subtitle = product.getSubTitle();
        this.pic = product.getPic();
        this.detailHtml = product.getDetailHtml();
        this.price = product.getPrice();
        this.promotionPrice = product.getPromotionPrice();
        this.commentCount=0;
    }

    public void setFrontCateAttributeDto(List<FrontCateAttributeDto> frontCateAttributeDto) {
        this.frontCateAttributeDto = new ArrayList<>();
        this.frontCateAttributeDto.addAll(frontCateAttributeDto);
    }

    public void setFrontCommentDtoList(List<FrontCommentDto> frontCommentDtoList) {
        this.frontCommentDtoList = new ArrayList<>();
        this.frontCommentDtoList.addAll(frontCommentDtoList);
        this.commentCount = frontCommentDtoList.size();
    }

    public void setStockList(List<PmsSkuStock> stockList) {
        this.stockList = new ArrayList<>();
        for (PmsSkuStock stock : stockList) {
            this.stockList.add(new FrontStockDto(stock));
        }
    }

}
